package com.yanqu.road.logic.activity.chuhan;

import java.util.HashMap;
import java.util.Map;

public class ChuHanMapGraph {
    private final Map<Integer, ChuHanMapNode> nodes = new HashMap<>();

    public ChuHanMapNode addNode(int cityId) {
        ChuHanMapNode node = nodes.get(cityId);
        if (node == null) {
            node = new ChuHanMapNode(cityId);
            nodes.put(cityId, node);
        }
        return node;
    }

    public void addEdge(int fromId, int toId) {
        ChuHanMapNode from = addNode(fromId);
        ChuHanMapNode to = addNode(toId);
        from.addEdge(to);
        to.addEdge(from);
    }

    public ChuHanMapNode getNode(int cityId) {
        return nodes.get(cityId);
    }

    public Map<Integer, ChuHanMapNode> getNodes() {
        return nodes;
    }
}
